package com.fable.sgms.user.service.impl;

import com.fable.common.base.BaseServiceImpl;
import com.fable.sgms.user.api.vo.UserVO;
import com.fable.sgms.user.dao.entity.SysUser;
import com.fable.sgms.user.dao.mapper.UserMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceimlp extends BaseServiceImpl implements com.fable.sgms.user.service.UserService {

    @Resource
    private UserMapper mapper;


    @Override
    public List<SysUser> findAll() {
        return mapper.selectAll();
    }

    @Override
    public UserVO save(UserVO vo) {

        mapper.insert(vo);
        return vo;
    }

    @Override
    public PageInfo<SysUser> query(SysUser entity) {
        return PageHelper.startPage(entity.getPageNum(), entity.getPageSize()).doSelectPageInfo(() -> mapper.select(entity));
    }

    @Override
    public SysUser findByUserName(String userName) {
        Assert.isTrue(StringUtils.hasText(userName),"用户名不能为空");
        SysUser entity = SysUser.builder().userName(userName).build();
        return mapper.selectOne(entity);
    }
}
